package com.chainyoung.component_tmtrade.ui.adapter;

import android.content.Intent;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chainyoung.component_tmtrade.R;
import com.chainyoung.component_tmtrade.bean.FiatOrder;
import com.chainyoung.component_tmtrade.constant.StringConstant;
import com.chainyoung.component_tmtrade.ui.activity.TradeFiatCurrencyOrderDetailActivity;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class TradeFiatCurrencyOrderAdapter extends BaseQuickAdapter<FiatOrder, BaseViewHolder> {


    SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public TradeFiatCurrencyOrderAdapter(@Nullable List<FiatOrder> data) {
        super(R.layout.tmtrade_list_order_item, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, final FiatOrder item) {

        helper.setText(R.id.tv_order_no, mContext.getString(R.string.tmtrade_order_no)+item.getOrderno());
        helper.setText(R.id.tv_status, getStautsStr(item.getStatus()));
//        helper.setTextColor(R.id.tv_status, item.getStatus() == 0 ? ContextCompat.getColor(mContext, R.color._F95A54) :
//                item.getStatus() == 1 ? ContextCompat.getColor(mContext, R.color._09C173) : ContextCompat.getColor(mContext, R.color._4486f5));

        helper.setText(R.id.tv_total_money, item.getMum_cny());

        helper.setText(R.id.tv_time, sd.format(new Date(item.getAddtime() * 1000)));

        helper.setText(R.id.tv_check_order,item.getTypename());
        helper.setBackgroundRes(R.id.tv_check_order,item.getType()==1?R.drawable.tmtrade_shape_green_solid:R.drawable.tmtrade_shape_red_solid);

        helper.getView(R.id.rl_order).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, TradeFiatCurrencyOrderDetailActivity.class);
                intent.putExtra(StringConstant.ID, item.getId());
                mContext.startActivity(intent);
            }
        });

    }

    private String getStautsStr(int status) {
        switch (status) {
            case 0:
            case 10:
                return mContext.getString(R.string.tmtrade_order_wait_for_pay);
            case 1:
                return mContext.getString(R.string.tmtrade_order_finished);
            case 2:
            case 3:
            case 4:
                return mContext.getString(R.string.tmtrade_order_closed);
            case 7:
                return mContext.getString(R.string.tmtrade_order_already_payed);
            case 8:
                return mContext.getString(R.string.tmtrade_wait_for_recieve);
            case 9:
                return mContext.getString(R.string.tmtrade_wait_recieve);
        }
        return null;
    }
}
